

;;====================================================
;; Routine to convert Table 1 from Simon:2006 into an IDL
;; structure for later use


data = read_fmr('./local/mrt/Simon_2006_Table1.txt')

help,data.data,/str

;; DATA.DATA is a structure of arrays --> I want an array of structures

ncp = n_elements(data.name)
q = '"'

type = size(data.data.(0)[0],/TNAME)
IF strcmp(type,'INT',3) THEN type = 'LONG'
command = 's06 = create_struct(IDL_VALIDNAME(data.name[0],/CONVERT_ALL),'+$
          type+'('+q+q+'))'
print,command
err = Execute(command)
print,err

FOR i=1L, ncp-1 DO BEGIN
   type = size(data.data.(i)[0],/TNAME)
   IF strcmp(type,'INT',3) THEN type = 'LONG'
   command = 's06 = create_struct(s06,IDL_VALIDNAME(data.name[i],/CONVERT_A),'+$
             type+'('+q+q+'))'
   err = Execute(command)
   
ENDFOR

help,s06,/str
s06 = replicate(s06,n_elements(data.data.(0)))
help,s06


;; Now, populate the structures
FOR i=0L, ncp-1 DO $
   s06.(i) = data.data.(i)

save,s06,filename='./ancillary/s06_kda_data.sav',/ver


ind = WHERE( strcmp(s06.desig,'(0)',3), nind) & print,nind

s06 = s06[ind]

sname = strmid(s06.name,6)

readcol,'./ancillary/BT12_clouds.txt',desig,name,l,b,d,i_mir,fbt12,fbt09,$
        format='a,a,f,f,f,x,x,x,f,f,f'

nbt12 = n_elements(name)

sind = lonarr(nbt12)

FOR i=0L, nbt12-1 DO BEGIN
   
   print,'>>'+name[i]+'<<'
   ind = WHERE( strcmp(sname,name[i],13), nind) & print,nind
   print,'>>'+sname[ind]+'<<'
   sind[i] = ind

ENDFOR

s06bt12 = s06[sind]

save,s06bt12,filename='./ancillary/s06bt12_data.sav',/ver



END


